package Cookie;

import Utils.CookieUtil;
import jakarta.servlet.*;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;

import java.io.IOException;

@WebServlet(value = "/Cookie/demo02")
public class CookieDemo02 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Cookie[] cookies = request.getCookies();
        Cookie key = CookieUtil.getCookie(cookies, "key");
        if (key != null) {
            response.getWriter().write(key.getValue()+request.getContextPath());
        }
        else {
           response.getWriter().write("没有找到key");
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
